<?php
require_once "./db_config.php";
$arr=[];
$name=$_POST['name'];
$ryxz=$_POST['ryxz'];
$i=0;
if($name){
    if($ryxz!=''){
        $sql="SELECT
            `$name`,
            count(1) AS counts
        FROM
            personalfiles 
        WHERE 
            ryxz='$ryxz' AND $name is not null
        GROUP BY
            `$name`";
        if($name=='ryxz'){
            $sql="SELECT
            `$name`,
            count(1) AS counts
            FROM
                personalfiles 
            GROUP BY
                `$name`";
        }else if($name=='state'){
            $sql="SELECT
            `$name`,
            count(1) AS counts
            FROM
                personalfiles 
            WHERE 
                ryxz='$ryxz'
            GROUP BY
                `$name`";
        }
        
        $result=mysqli_query($conn,$sql);
        if (mysqli_num_rows($result) > 0) {
        // 输出数据
        while($row = mysqli_fetch_array($result)) {
            array_push($arr,$row);
        }
        } else {
        echo "0 结果";
        }
    }else{
            $sql="SELECT
            `$name`,
            count(1) AS counts
            FROM
                personalfiles 
            GROUP BY
                `$name`";
            // echo $sql;
            $result=mysqli_query($conn,$sql);
            if (mysqli_num_rows($result) > 0) {
            // 输出数据
            while($row = mysqli_fetch_array($result)) {
                     array_push($arr,$row);  
            }
            } else {
            echo "0 结果";
            }
    }
}
echo json_encode($arr,JSON_UNESCAPED_UNICODE);
mysqli_close($conn);
?>